package com.rabbitmq.extension.config;

import com.rabbitmq.extension.constant.Constants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DelayedConfig {
    @Bean("delayedExchange")
    //使用了延迟消息插件
    public Exchange delayedExchange(){
        return ExchangeBuilder.directExchange(Constants.DELAY_EXCHANGE).durable(true).delayed().build();
    }

    @Bean("delayedQueue")
    public Queue delayedQueue(){
        return QueueBuilder.durable(Constants.DELAY_QUEUE).build();
    }

    @Bean("delayedBinding")
    public Binding delayedBinding(@Qualifier("delayedExchange") Exchange exchange,@Qualifier("delayedQueue") Queue queue){
        return BindingBuilder.bind(queue).to(exchange).with("delayed").noargs();
    }
}
